<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="https://cdn.bootcdn.net/ajax/libs/axios/0.27.2/axios.min.js"></script>
</head>
<body>
    <h1>axios的默认配置</h1>
    <button>学生信息</button>
    <button>会员信息</button>
    <script>
        // axios的默认配置

        // 初始化当前网站axios的默认基础配置
        axios.defaults.method = "get";
        axios.defaults.baseURL = "http://localhost:3000/";

        // 获取上面两个按钮，并分别绑定点击事件
        const btns = document.querySelectorAll("button");
        btns[0].onclick = async function(){
            //const res = await axios({url: "/stu"});
            //console.log(res);
            // 使用解构赋值
            let {data, status} = await axios({url: "/stu"});
            console.log(data);
            console.log(status);
        }

        btns[1].onclick = async function(){
            //const res = await axios({url: "/users"});
            //console.log(res);
            // 使用解构赋值
            let {data, status} = await axios({url: "/users"});
            console.log(data);
            console.log(status);
        }

        




        // 未来的目录和文件的路径合并，使用：path.join(__dirname, "a/b/c.txt");
    </script>
</body>
</html>